package com.welove.activity;

import com.welove.R;
import com.welove.fragments.LoadFragment;
import com.welove.fragments.UnLoginFragment;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.widget.ViewFlipper;

public class WelcomeActivity extends BaseActivity {
	private static final String TAG=WelcomeActivity.class.getSimpleName();
	
	private boolean isLogin=false;

	@Override
	protected void installViews() {
		setContentView(R.layout.activity_welcome);
		
		initFragment();
	}

	private void initFragment() {
		/*
		 * 判断是否登录
		 */
		
		isLogin = getBoolPref("UserInfo", "lg_status");
		
		FragmentManager fm = getSupportFragmentManager();
		FragmentTransaction ft = fm.beginTransaction();
		if (isLogin) {
			/*
			 * 处于登录状态就定位加载..完成后跳转至主页面
			 */
			LoadFragment loadFragment = (LoadFragment) fm
					.findFragmentByTag("load");
			if (loadFragment != null)
				ft.detach(loadFragment);
			if (loadFragment == null) {
				loadFragment = new LoadFragment();
				ft.add(R.id.frame_welcome, loadFragment, "load");
			} else {

				ft.attach(loadFragment);
			}
		} else {
			/*
			 * 未登录状态加载推荐信息，显示登录注册界面
			 */
			UnLoginFragment nolgFragment = (UnLoginFragment) fm
					.findFragmentByTag("nolg");
			if (nolgFragment != null)
				ft.detach(nolgFragment);
			if (nolgFragment == null) {
				nolgFragment = new UnLoginFragment();
				ft.add(R.id.frame_welcome, nolgFragment, "nolg");
			} else {

				ft.attach(nolgFragment);
			}
		}
		ft.commit();
	}
	
	@Override
	protected void initTitleBar() {
		super.initTitleBar();
		mTitleBar.titlebar_tv_center.setText("喜恋姻缘");
		mTitleBar.titlebar_btn_right.setVisibility(ViewFlipper.GONE);
		
		mTitleBar.titlebar_btn_left.setVisibility(ViewFlipper.GONE);
	}

	@Override
	protected void registerEvents() {
		// TODO Auto-generated method stub

	}

}
